package cz.muni.fi.pa165.sme.services.converter;

import cz.muni.fi.pa165.sme.api.to.SportActivityRecordTO;
import cz.muni.fi.pa165.sme.dao.entity.SportActivityRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

/**
 * @author jirankova
 */
public class SportActivityRecordTO2SportActivityRecordConverter implements Converter<SportActivityRecordTO, SportActivityRecord> {

	@Autowired private SportActivityTO2SportActivityConverter sportActivityConverter;
	@Autowired private UserTO2UserConverter userConverter;

	@Override
	public SportActivityRecord convert(final SportActivityRecordTO source) {
		if(source == null) {
			return null;
		}

		final SportActivityRecord sportActivityRecord = new SportActivityRecord();

		sportActivityRecord.setActivityStart(source.getActivityStart());
		sportActivityRecord.setActivityStop(source.getActivityStop());
		sportActivityRecord.setDistance(source.getDistance());
		sportActivityRecord.setDuration(source.getDuration());
		sportActivityRecord.setId(source.getId());
		sportActivityRecord.setSportActivity(sportActivityConverter.convert(source.getSportActivity()));
		sportActivityRecord.setUser(userConverter.convert(source.getUser()));

		return sportActivityRecord;
	}
}
